package com.lagou.edu.wwyan.mongo;

import com.lagou.edu.wwyan.mongo.bean.Resume;
import com.lagou.edu.wwyan.mongo.repository.ResumeRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.domain.Example;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;

@SpringBootApplication
public class MongoApplication {

	public static void main(String[] args) {
		ConfigurableApplicationContext applicationContext = SpringApplication.run(MongoApplication.class, args);
		ResumeRepository repository = applicationContext.getBean(ResumeRepository.class);
		System.out.println(repository.findAll());
		//清空数据
		repository.deleteAll();
//		//生成数据
//		Random random = new Random();
//		List<Resume> resumes = new ArrayList<>();
//		for (int i = 0; i < 100; i++) {
//			Resume resume = new Resume("test" + i, random.nextDouble() * 20000);
//			resumes.add(resume);
//		}
//		repository.insert(resumes);
//		//查询一条
//		Optional<Resume> on = repository.findOne(Example.of(new Resume("test1", null)));
//		System.out.println("查询test1:"+on);
//		//查询所有
		System.out.println(repository.findAll());

	}

}
